﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using amazingfishing.senes;
using System.Diagnostics;

namespace amazingfishing
{
    
    /// <summary>
    /// 这是游戏的主类型
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont scoreFont;//字体

      //  GraphicsDeviceManager graphics;
        public enum GameState { on_menu, world_map, option, exit ,scene1, scene2, scene3};
        public GameState currentState;
        private GameState preState;

        public Game1()
        {
            currentState = GameState.on_menu;
            preState = currentState;

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Windows Phone 的默认帧速率为 30 fps。
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // 延长锁定时的电池寿命。
            InactiveSleepTime = TimeSpan.FromSeconds(1);

            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth = 480;

        }

        /// <summary>
        /// 允许游戏在开始运行之前执行其所需的任何初始化。
        /// 游戏能够在此时查询任何所需服务并加载任何非图形
        /// 相关的内容。调用 base.Initialize 将枚举所有组件
        /// 并对其进行初始化。 
        /// </summary>
        protected override void Initialize()
        {
            // TODO: 在此处添加初始化逻辑
            //设置触摸板手势可用
            TouchPanel.EnabledGestures = GestureType.Tap | GestureType.Hold;

            MainMenu mainMenu = new MainMenu(this);
            mainMenu.Initialize();
            Components.Add(mainMenu);

            base.Initialize();
        }

        /// <summary>
        /// 对于每个游戏会调用一次 LoadContent，
        /// 用于加载所有内容。
        /// </summary>
        protected override void LoadContent()
        {
            // 创建新的 SpriteBatch，可将其用于绘制纹理。
            spriteBatch = new SpriteBatch(GraphicsDevice);

            scoreFont = Content.Load<SpriteFont>(@"Fonts\Score");
            // TODO: 在此处使用 this.Content 加载游戏内容
        }

        /// <summary>
        /// 对于每个游戏会调用一次 UnloadContent，
        /// 用于取消加载所有内容。
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: 在此处取消加载任何非 ContentManager 内容
        }

        /// <summary>
        /// 允许游戏运行逻辑，例如更新全部内容、
        /// 检查冲突、收集输入信息以及播放音频。
        /// </summary>
        /// <param name="gameTime">提供计时值的快照。</param>
        protected override void Update(GameTime gameTime)
        {
            if (currentState != preState)
            {
                preState = currentState;

                switch (currentState)
                {
                    case GameState.on_menu:
                        Components.Clear();
                        MainMenu mainMenu = new MainMenu(this);
                        mainMenu.Initialize();
                        Components.Add(mainMenu);
                        break;
                    case GameState.world_map:
                        Components.Clear();
                        WorldMap worldMap = new WorldMap(this);
                        worldMap.Initialize();
                        Components.Add(worldMap);
                        break;
                    case GameState.scene1:
                        Components.Clear();
                        Fishing fishing = new Fishing(this);
                        fishing.Initialize();
                        Components.Add(fishing);
                        break;
                    case GameState.scene2:
                        Components.Clear();
                        Fishing3 fishing2 = new Fishing3(this);
                        fishing2.Initialize();
                        Components.Add(fishing2);
                        break;
                    case GameState.scene3:
                        Fishing2 fishing3 = new Fishing2(this);
                        fishing3.Initialize();
                        Components.Add(fishing3);
                        break;
                    case GameState.option:
                        option Option = new option(this);
                        Option.Initialize();
                        Components.Add(Option);
                        break;
                    case GameState.exit:
                        this.Exit();
                        break;
                    default:
                        break;
                }
            }

            base.Update(gameTime);
        }

        /// <summary>
        /// 当游戏该进行自我绘制时调用此项。
        /// </summary>
        /// <param name="gameTime">提供计时值的快照。</param>
        protected override void Draw(GameTime gameTime)
        {
            //switch (currentState)
            //{
            //    case GameState.world_map:
            //        GraphicsDevice.Clear(Color.AliceBlue);
            //        Components.Remove(mainMenu);

            //        spriteBatch.Begin();
            //        spriteBatch.Draw(mapTexture, new Rectangle(0, 0, 480, 800), null, Color.White,
            //            0, Vector2.Zero, SpriteEffects.None, 0);
            //        spriteBatch.End();
            //        break;
            //    case GameState.option:
            //        string text = "选项啊选项";
            //        spriteBatch.DrawString(scoreFont, text, new Vector2((Window.ClientBounds.Width / 2 -
            //            scoreFont.MeasureString(text).X / 2), (Window.ClientBounds.Height / 2 - scoreFont.MeasureString(text).Y / 2)),
            //            Color.SaddleBrown);
            //        break;    
            //}
            // TODO: 在此处添加绘图代码

            base.Draw(gameTime);
        }
     
    }
}
